#!/bin/bash

# AirChina-Vue at Tomcat8 with Docker 部署脚本
echo ==================================================
echo Script startup for deploy AirChina-Vue at Tomcat8 with Docker
echo ==================================================

# Tomcat8镜像库地址
TOMCAT8_DOCKER_REGISTRY=daocloud.io/library/tomcat
# Tomcat8镜像版本
TOMCAT8_DOCKER_VERSION=8.5.15-jre8
# Tomcat7的Docker实例名称
TOMCAT8_DOCKER_INSTANCE_NAME=tomcat8-airchina-vue
# Tomcat7物理机HTTP映射端口
TOMCAT8_PHYSICAL_MACHINE_HTTP_PORT=8001
# Tomcat7虚拟机HTTP映射端口
TOMCAT8_VIRTUAL_MACHINE_HTTP_PORT=8080
# Tomcat7物理机中web-apps路径
TOMCAT8_PHYSICAL_MACHINE_WEB_APPS_PATH=/home/air-china-vue-web-app/web-app
# Tomcat7虚拟机中web-apps路径
TOMCAT8_VIRTUAL_MACHINE_WEB_APPS_PATH=/usr/local/tomcat/webapps/airchina

############################ installing start ############################
echo -e "-------------------- installing\n"

echo "-------------------- pulling tomcat8 docker image"
docker pull $TOMCAT8_DOCKER_REGISTRY:$TOMCAT8_DOCKER_VERSION
echo -e "-------------------- pull success.\n"
sleep 3

echo "-------------------- running AirChina-Vue at tomcat8"
docker run -d -p $TOMCAT8_PHYSICAL_MACHINE_HTTP_PORT:$TOMCAT8_VIRTUAL_MACHINE_HTTP_PORT -v $TOMCAT8_PHYSICAL_MACHINE_WEB_APPS_PATH:$TOMCAT8_VIRTUAL_MACHINE_WEB_APPS_PATH:rw --name $TOMCAT8_DOCKER_INSTANCE_NAME --restart always --privileged=true $TOMCAT8_DOCKER_REGISTRY:$TOMCAT8_DOCKER_VERSION
echo -e "-------------------- run success.\n"
sleep 3

echo -e "-------------------- install completed!\n"
############################ installing end ############################

############################ validating start ############################
echo -e "-------------------- validating\n"

echo -e "-------------------- validating tomcat8 run status\n"
docker ps -a | grep "$TOMCAT8_DOCKER_INSTANCE_NAME"
sleep 3

echo -e "-------------------- validate completed!\n"
############################ validating end ############################

echo =================================================
echo Deploy AirChina-Vue at Tomcat8 with Docker completed!
echo =================================================